import download from '@img/document-manage/download.png'
import history from '@img/document-manage/history.png'
import open from '@img/document-manage/open.png'
import remove from '@img/document-manage/remove.png'
import { Tooltip } from 'antd'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== $Lazy
const confirm = $Lazy.file(()=>import('@antd/confirm'))
// =====================================================================
const data = [
	{label: '下载文件', value: download, onClick: ({uuid}) => {
		$http.submit(null,'doc-file-list/download',{param:{uuids:[uuid]}}).then((data)=>{
			data.forEach(v=>window.open(v))
			$fn.msg.success('文件下载成功')
		})
	} },
	{label: '打开文件', value: open, onClick: ({uuid, that}) => {
		const baseUrl = $fn.getRoot().root+'/workbench/document-manage'
		that.props.history.push(baseUrl+`/file-detail?uuid=${uuid}&isEdit=false&showEdit=true&showEmpower=false&folder=false`)
	}},
	{label: '历史记录', value: history, onClick: ({uuid, that}) => {
		that.historyVersionRef.open(uuid)
	}},
	{label: '删除文件', value: remove, onClick: ({uuid, that}) => {
		confirm.then( f => {
			f({
				msg:'是否删除该文件？',
				onOk: close => {
					$http.submit(null,'doc-file-list/del',{param:{uuids:[uuid]}}).then((data)=>{
						close()
						$fn.msg.success('文件删除成功')
						that.fetch()
					})
				}
			})
		})
	}},
]
const Index = that => {
	return { width:130, render: (text, { uuid, file_type }) => {
		return (
			<div className='fxm'>
				{
					data.map((v, i) => <Tooltip key={i} title={v.label} mouseEnterDelay={1} className='rel mr5'>
						<img onClick={() => v.onClick({uuid, that})} src={v.value} alt='' />
					</Tooltip>)
				}
				
			</div>
		)
	} }
}

export default Index